package com.woniuxy.commons.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

@Configuration
public class ObjectRedisUtil {
//    @Resource
//    private RedisConnectionFactory rcff;

    @Bean("objectredis")
    public RedisTemplate<String,Object> getObjectToJson(RedisConnectionFactory rcf){
        RedisTemplate<String,Object> rt=new RedisTemplate<String,Object>();
        rt.setKeySerializer(RedisSerializer.string());
        rt.setValueSerializer(RedisSerializer.json());
        rt.setHashKeySerializer(RedisSerializer.string());
        rt.setHashValueSerializer(RedisSerializer.string());
        rt.setConnectionFactory(rcf);
        rt.afterPropertiesSet();
        return rt;
    }

}
